<?php
	class Module_model extends CI_Model{
		
		public function __construct(){
			$this->load->database();
		}
		
		public function getModuleList($id=FALSE){
			if($id === FALSE){
				$query = $this->db->get('module');
				return $query->result_array();
			}
			$query = $this->db->get_where('module', array('id' => $id));
			return $query->row_array();
		}
		
		public function save(){
			$id = $this->input->post('id');
			$data = array(
				"name" => $this->input->post('name'),
				"description" => $this->input->post('description'),
				"route" => $this->input->post("route")
			);
			if(empty($id))
				return $this->db->insert('module', $data);
			else{
				$this->db->where('id', $id);
				return $this->db->update('module', $data);
			}
		}
		
		public function getModuleForLogin($id){
			/*$this->db->select('id', 'name', 'route');
			$ids = explode(",", $id);
			$this->db->where_in("id", $ids);
			$query = $this->db->get();*/
			//$ids = explode(",", $id);
			$query = $this->db->query("SELECT `id`, `name`, `route` FROM `module` WHERE `id` IN ($id)");
			return $query->result_array();	
		}
		
	}
?>